// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
function PlayerStateHook()
{
	//当在这个状态时，静止
	hSpeed = 0;
	vSpeed = 0;
	//当第一次到达这个状态
	if(sprite_index != sPlayerHook)
	{
		hook = 0;
		hookX = 0;
		hookY = 0;
		hookStatus = HOOKSTATUS.EXTENDING;
		hookedEntity = noone;
		//更新精灵图
		sprite_index = sPlayerHook;
		image_index = CARDINAL_DIR;
		image_speed = 0;
	}
	
	//延申或者收缩过程
	var _speedHookTemp = speedHook;
	if(hookStatus != HOOKSTATUS.EXTENDING) _speedHookTemp *= -1; // 如果钩子当前状态不是延申，那么速度取反方向
	//hook为钩子当前长度
	hook += _speedHookTemp;
	//通过精灵图序列号来判断钩子的方向,并赋值钩子长度于坐标中
	switch(image_index)
	{
		case 0 : hookX = hook; break;
		case 1 : hookY = -hook; break;
		case 2 : hookX = -hook; break;
		case 3 : hookY = hook; break;
	}
	//钩子发射状态机
	switch(hookStatus)
	{
		case HOOKSTATUS.EXTENDING :
		{
			//如果什么也每勾到
			if(hook >= distanceHook) hookStatus = HOOKSTATUS.MISSED;
			
			//碰撞检测
			var _hookHit = collision_circle(x + hookX, y + hookY, 4, pEntity, false, true);
			//如果碰撞到了实体并且这个实体不是现在手上正在拿着的东西
			if( _hookHit != noone && global.iLifted != _hookHit)
			{
				//接下来的行动取决于这个实体的entityHookable的值
				/*
////////////////这个位置不能用with(_hookHit)啊！！！！！！
				*/
					switch(_hookHit.entityHookable)
					{						
						case 1 : 
						{
							hookStatus = HOOKSTATUS.PULLTOPLAYER;
							hookedEntity = _hookHit;
							break;
						}
						case 2 :
						{
							hookStatus = HOOKSTATUS.PULLTOENTITY;
							hookedEntity = _hookHit;
							break;
						}
						//当entityHookable既不是1也不是2时
						default :
						{
							//如果碰撞到的实体是enemy
							if(object_is_ancestor(_hookHit.object_index, pEnemy))
							{
								HurtEnemy(_hookHit, 1, id, 5);
								
							}
							else//如果不是enemy
							{
								//如果碰撞实体有hit脚本
								if(_hookHit.entityHitScript != -1)
								{
									with(_hookHit) script_execute(entityHitScript);
									
								}
							}
							
							hookStatus = HOOKSTATUS.MISSED;//不管如何都要收回钩子喽
							break;
						}
					
					}

			}
			break;//case HOOKSTATUS.EXTENDING
		}
		case HOOKSTATUS.PULLTOPLAYER :
		{
			//将勾中的目标拉向player
			with(hookedEntity)
			{
				//目标坐标位于钩子坐标处
				x = other.x + other.hookX;
				y = other.y + other.hookY;
			}
			break;
		}
		case HOOKSTATUS.PULLTOENTITY :
		{
			switch(image_index)
			{
				case 0 : x += speedHook; break;
				case 1 : y -= speedHook; break;
				case 2 : x -= speedHook; break;
				case 3 : y += speedHook; break;///这里case3写成4了，怪不得拉不过去
			}
			break;
		}
		
	}
	//钩子收缩完毕
	if(hook <= 0)
	{
		hookedEntity = noone;
		state = PlayerStateFree;
	}
	
}